package com.genITeam.ria.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import com.genITeam.ria.bl.SearchForumBL;
import com.genITeam.ria.exception.NGFException;
import com.genITeam.ria.utility.Utility;
import com.genITeam.ria.vo.Posts;

public class SearchForumAction extends AbstractAction {

	public SearchForumAction() {

		BasicConfigurator.configure();

	}

	Logger logger = Logger.getLogger(SearchForumAction.class);

	/**
	 * handleSearchForum used to get Parameters from Request object and write
	 * the resulting XML to Request
	 * 
	 * @param request,
	 *            response
	 * 
	 * @return none
	 * @throws none
	 */

	public void handleSearchForum(HttpServletRequest request,
			HttpServletResponse response) throws NGFException {

		SearchForumBL searchForumBL = new SearchForumBL();

		try {
			logger.info("handleSearchForum");
			Posts posts = new Posts();

			String title = request.getParameter("title");
			String message = request.getParameter("message");

			logger.debug("title = " + title);
			logger.debug("message = " + message);

			posts.setTitle(Utility.getStringValue(title, ""));
			posts.setMessage(Utility.getStringValue(message, ""));

			this.initAction(request, response);
			this.writeResponse(searchForumBL.searchForum(posts));

		} catch (NGFException e) {
			this.initAction(request, response);
			this.writeResponse("<error>" + e.getErrorMessage() + "</error>");
			System.out.print("Search Forum Excepton = " + e.getMessage());
		} catch (Exception e) {
			logger.error("Exception=" + e.toString());
			this.initAction(request, response);
			this.writeResponse("<error>" + e.getMessage() + "</error>");
			System.out.print("Search Forum Excepton = " + e.getMessage());
		}

	}
}
